#include <windows.h>		// Header File For Windows
#include <mmsystem.h>
#include <direct.h>
#include <stdio.h>	
#include <fstream>
#include <time.h>
#include <math.h>
#include <gl\gl.h>			// Header File For The OpenGL32 Library
#include <gl\glu.h>			// Header File For The GLu32 Library
#include <gl\glaux.h>		// Header File For The Glaux Library
#include "dsound.h"
#include "dmusic.h"
#include "define.h" 
#include "resource.h"  

using namespace std;

//VARIABLES
extern HDC			hDC;		// Private GDI Device Context
extern HGLRC		hRC;		// Permanent Rendering Context
extern HWND		hWnd;		// Holds Our Window Handle
extern HINSTANCE	hInstance;		// Holds The Instance Of The Application

extern bool	keys[256];			// Array Used For The Keyboard Routine
extern bool	active;		// Window Active Flag Set To TRUE By Default
extern bool	fullscreen;	// Fullscreen Flag Set To Fullscreen Mode By Default
extern GLuint texture[1];
extern GLfloat movement;
extern float distance;

extern int W_WIDTH;
extern int W_HEIGHT;
extern float b_size;
extern float scale;

extern bool follow;
extern bool firstPerson;

//FUNCTIONS
LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc
AUX_RGBImageRec *LoadBMP(char *Filename);
GLuint LoadGLTextures(char *filename);
void shutdown();
void game();
void titlescreen();
void loadcustom();


//////////////////////////////////////////////////////
//CLASSES
//////////////////////////////////////////////////////

/**************PACHEAD CLASS****************/
class Pachead
{
public:
	//(x,y) coordinates
	GLfloat x;
	GLfloat y;
	
	//sprites and sounds
	GLuint sprites[6][2];
	CSound *sounds[11];
	CSound *dygersound[6];
	
	//position on the map
	int posx;  
	int posy;
	//start position on map
	int initposy;
	int initposx;

	char state;    
	int direction; 
	int lives;
	int health;
	int level;    //current level
	int time;     //time to keep track of powerup length
	GLfloat speed;//how fast pachead moves per frame
	DWORD powertimer; //time that each power-up has

	int score;

	//true/false situations for pachead
	bool moving;
	bool warp;
	bool swtch;
	bool count1;
	bool count2;

	//functions
	void input();
	int drawpachead();
	void loadsprites();
	void death();
	void loaddyger();

};


/*****************ENEMY CLASSES********************/
class Enemy
{
public:
	GLfloat x;
	GLfloat y;

	int posx;
	int posy;

	int initposx;
	int initposy;

	int timer;
	bool hit;

	int id;

	char state;
	int direction;

	GLfloat speed;

	void collision();

	static GLuint attacksprites[5][2];
	static GLuint tracersprites[5][2];
	static GLuint guardsprites[5][2];
	static GLuint fearsprites[5][2];
	static GLuint racersprites[5][2];
	static CSound *sounds[5];
	
	static void loadsprites();
	
	virtual void ai();
	virtual void drawenemy();
};

/**************ENEMY CHILD CLASSES*******************/
class Attack : public Enemy
{
public:
	void ai();
	void drawenemy();
};

class Fear : public Enemy
{
public:
	void ai();
	void drawenemy();
};

class Guard : public Enemy
{
public:
	void ai();
	void drawenemy();
};

class Tracer : public Enemy
{
public:
	void ai();
	void drawenemy();
};
  
class Racer : public Enemy
{
public:
	void ai();
	void drawenemy();
};


/******************MAP CLASS**************************/
class Map
{
public:

	fstream infile;
	GLuint maptiles[TILENUM][2];

	int enemynum;
	int pacnum;

	int mapnum;

	int x[SIZEY][SIZEX];
	int y[SIZEY][SIZEX];

	char tiles[SIZEY][SIZEX];
	char special[SIZEY][SIZEX];
	int loadmap(char *name);
	void drawmap();
	int nextmap();
	int prevmap();
	void loadmaptiles();

};


/*******************DISPLAYNG NUMBERS CLASS**********************/
class CNum
{
public:
	
	GLuint digits[10];
	
	void loaddigits();
	void drawnumber(int num, int x, int y);
};

/*******************DISPLAYING GAME INFORMATION CLASS**********************/
class Info
{
public:
	GLuint pictures[5];

	int px,py,lx,ly,mx,my,sx,sy,lvx,lvy,hx,hy,plx,ply;


	void loadpictures();
	void drawinfo();
	void mapintro();
	void gameover();



};


///////////////////
//global variables
///////////////////
extern Enemy *enemies[MAXENEMY];
extern Map map;
extern Pachead pachead;
extern CNum cnum;
extern Info info;
extern int numenemy;
extern int difficulty;
extern DWORD framerate;
extern int framecount;
extern int midimusic[NUMMUSIC];
extern int songnum;
extern int highscore;

